<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
  <head>
	<meta charset="utf-8">
    <title>circle packing</title>
	<script src="../js/d3.v3.min.js"></script>

  <link rel="stylesheet" href="../circlepacking/css/d3.circlepacking.css" type="text/css"></link>
 
<style>
#chartPanel {
	float: left; 
}
#controlPanel { 
	position: absolute;
	right: 10px;
	top: 10px;
	width: 100px;
}
.legend {
	font-size: 20px;
} 
</style>
  <s:head/>
  </head>

  <body>
  
  <div id="chartPanel"></div>
  <div id="controlPanel">
  	
  	<form action="<s:url action="fileUpload" namespace="/circlepacking"/>" method="post" enctype="multipart/form-data">
  		<input type="hidden" name="destPage" value="<%= request.getServletPath()%>" />
  		<div>
  			<label for="dataFile">data file</label>
  			<s:file name="data" />
  		</div>
  		<div>
  			<input type="submit"/>
  		</div>
  	</form>
  </div>
  
<script>

var diameter = 860,
	format = d3.format(",d");
	
var pack = d3.layout.pack()
			.size([diameter - 4, diameter - 4])
			.value(function (d) { return d.size; });

var svg = d3.select("#chartPanel").append("svg")
			.attr("width", diameter)
			.attr("height", diameter)
			.append("g")
			.attr("transform", "translate(2, 2)");

d3.json('<s:property value="#session['CURRENT_FILE']"/>', function (error, root) {
	
	var node = svg.datum(root).selectAll(".node")
    .data(pack.nodes)
  .enter().append("g")
    .attr("class", function(d) { return d.children ? "node" : "leaf node"; })
    .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });

node.append("title")
    .text(function(d) { return d.name + (d.children ? "" : ": " + format(d.size)); });

node.append("circle")
    .attr("r", function(d) { return d.r; });

node.filter(function(d) { return !d.children; }).append("text")
    .attr("dy", ".3em")
    .style("text-anchor", "middle")
    .text(function(d) { return d.name.substring(0, d.r / 3); });
});

d3.select(self.frameElement).style("height", diameter + "px");

</script>
  
  
  </body>
</html>



















